package com.collect.cameroon.zhiScene.zhiWidget.zhiPhonebookView;

import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.collect.cameroon.R;
import com.collect.cameroon.zhiBean.zhiReceive.ZHIRPhoneBookEntity;

public class ZHIPhoneBookAdjuster extends BaseQuickAdapter<ZHIRPhoneBookEntity, BaseViewHolder> {

    public ZHIPhoneBookAdjuster() {
        super(R.layout.item_phonebook_list, null);
    }

    private OnPhoneBookItemClickListener mOnPhoneBookItemClickListener;

    public static final String ITEM_TYPE_CALL_PHONE = "CALL_PHONE";
    public static final String ITEM_TYPE_RECORD_TAG = "RECORD_TAG";
    public static final String ITEM_TYPE_RECORD_WHATSAPP = "RECORD_WHATSAPP";

    @Override
    protected void convert(BaseViewHolder helper, final ZHIRPhoneBookEntity zhirPhoneBookEntity) {
        try {
            TextView tv_often_used = helper.getView(R.id.tv_often_used);
            tv_often_used.setVisibility(zhirPhoneBookEntity.isOftenUsed() ? View.VISIBLE : View.GONE);

            TextView tv_relationship = helper.getView(R.id.tv_relationship);
            tv_relationship.setVisibility(TextUtils.isEmpty(zhirPhoneBookEntity.getRelation()) ? View.GONE : View.VISIBLE);

            helper.setText(R.id.tv_name, zhirPhoneBookEntity.getContactName());
            helper.setText(R.id.tv_phone, zhirPhoneBookEntity.getContactMobileEncryptFormatter());
            helper.setText(R.id.tv_relationship, zhirPhoneBookEntity.getRelation());

            helper.addOnClickListener(R.id.iv_ipl_call_phone);
            helper.addOnClickListener(R.id.iv_ipl_record_tag);
            helper.addOnClickListener(R.id.iv_ipl_record_tag);

            if (mOnPhoneBookItemClickListener != null) {
                helper.getView(R.id.iv_ipl_call_phone).setOnClickListener(view -> mOnPhoneBookItemClickListener.OnItemClick(zhirPhoneBookEntity, ITEM_TYPE_CALL_PHONE));
                helper.getView(R.id.iv_ipl_record_tag).setOnClickListener(view -> mOnPhoneBookItemClickListener.OnItemClick(zhirPhoneBookEntity, ITEM_TYPE_RECORD_TAG));
                helper.getView(R.id.iv_ipl_whatsapp).setOnClickListener(view -> mOnPhoneBookItemClickListener.OnItemClick(zhirPhoneBookEntity, ITEM_TYPE_RECORD_WHATSAPP));
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void setPhoneBookItemClickListener(OnPhoneBookItemClickListener onOrderItemClickListener) {
        this.mOnPhoneBookItemClickListener = onOrderItemClickListener;
    }

    public interface OnPhoneBookItemClickListener {
        void OnItemClick(ZHIRPhoneBookEntity zhirPhoneBookEntity, String type);
    }
}